<template>
  <el-menu
    :default-active="activeIndex"
    class="sidebar"
    :collapse="isCollapse"
    router
  >
    <el-menu-item index="/">
      <el-icon><HomeFilled /></el-icon>
      <span>首页</span>
    </el-menu-item>

    <el-menu-item index="/hot">
      <el-icon><Star /></el-icon>
      <span>热门推荐</span>
    </el-menu-item>

    <el-menu-item index="/new">
      <el-icon><Goods /></el-icon>
      <span>新品上市</span>
    </el-menu-item>

    <el-divider />

    <!-- AI客服入口 -->
    <el-menu-item index="/ai-chat" class="ai-chat-item">
      <el-icon><Service /></el-icon>
      <span>AI智能客服</span>
      <el-badge 
        :value="unreadCount"
        :hidden="!unreadCount" 
        class="ai-badge" 
        type="danger"
      />
    </el-menu-item>

    <el-divider />

    <el-menu-item index="/wishlist">
      <el-icon><Star /></el-icon>
      <span>我的收藏</span>
    </el-menu-item>

    <el-menu-item index="/orders">
      <el-icon><List /></el-icon>
      <span>我的订单</span>
    </el-menu-item>

    <el-menu-item index="/recent-views">
      <el-icon><View /></el-icon>
      <span>最近浏览</span>
    </el-menu-item>
  </el-menu>

  <!-- 折叠按钮 -->
  <div class="collapse-btn" @click="toggleCollapse">
    <el-icon>
      <component :is="isCollapse ? 'Expand' : 'Fold'" />
    </el-icon>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import {
  HomeFilled,
  Star,
  Goods,
  Service,
  List,
  View,
  Expand,
  Fold
} from '@element-plus/icons-vue'

const route = useRoute()
const router = useRouter()
const activeIndex = ref(route.path)
const isCollapse = ref(false)
const unreadCount = ref(1) // 可以通过API获取未读消息数量

// 监听路由变化
watch(() => route.path, (newPath) => {
  activeIndex.value = newPath
})

const toggleCollapse = () => {
  isCollapse.value = !isCollapse.value
}
</script>

<style scoped>
.sidebar {
  height: 100%;
  border-right: solid 1px var(--el-menu-border-color);
  transition: width 0.3s;
}

.ai-chat-item {
  position: relative;
  color: var(--el-color-primary);
}

.ai-chat-item:hover {
  background-color: var(--el-color-primary-light-9);
}

.ai-badge {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.el-menu--collapse .ai-badge {
  right: 5px;
}

.el-menu-item {
  display: flex;
  align-items: center;
  padding: 0 20px;
}

.el-icon {
  margin-right: 8px;
  font-size: 18px;
}

.collapse-btn {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  background-color: var(--el-color-primary-light-9);
  transition: all 0.3s;
}

.collapse-btn:hover {
  background-color: var(--el-color-primary-light-7);
}

/* 折叠时的样式 */
.el-menu--collapse {
  width: 64px;
}

.el-menu--collapse .el-menu-item span {
  display: none;
}

.el-divider {
  margin: 8px 0;
}

/* 响应式设计 */
@media screen and (max-width: 768px) {
  .sidebar {
    width: 64px;
  }

  .el-menu-item span {
    display: none;
  }

  .collapse-btn {
    display: none;
  }
}
</style> 